<template>
  <header>
    后台管理系统
    <div class="logout" @click="logout">退出</div>
  </header>
  <div class="container">
    <div class="menu">
      <div
        :class="{ active: route.path == '/admin/homepage' }"
        @click="$router.push('/admin/homepage')"
      >
        系统首页
      </div>
      <div
        :class="{ active: route.path == '/admin/user' }"
        @click="$router.push('/admin/user')"
      >
        用户管理
      </div>
      <div
        :class="{ active: route.path == '/admin/article' }"
        @click="$router.push('/admin/article')"
      >
        文章管理
      </div>
      <div
        :class="{ active: route.path == '/admin/articleAdudit' }"
        @click="$router.push('/admin/articleAdudit')"
      >
        审核记录
      </div>
      <div
        :class="{ active: route.path == '/admin/type' }"
        @click="$router.push('/admin/type')"
      >
        类别管理
      </div>
      <div
        :class="{ active: route.path == '/admin/notice' }"
        @click="$router.push('/admin/notice')"
      >
        公告管理
      </div>
    </div>
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>
<script setup>
import { onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();
const logout = () => {
  localStorage.removeItem("adminlogined");
  router.push("/adminLogin");
};
onMounted(() => {
  localStorage.getItem("adminlogined") || router.push("/adminLogin");
});
</script>

<style lang="less" scoped>
header {
  height: 60px;
  background-color: #252525;
  color: #fff;
  padding: 0 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}
.container {
  display: flex;
  height: calc(100vh - 60px);
  .menu {
    width: 200px;
    background-color: #cecece;
    align-items: center;
    flex-flow: column;
    display: flex;
    .active {
      background-color: #8b8b8b;
      &:hover {
        background-color: #8b8b8b;
      }
    }
    div {
      height: 70px;
      display: flex;
      align-items: center;
      justify-content: center;
      user-select: none;
      cursor: pointer;
      width: 100%;
      transition: all 0.3s ease-in-out;
      &:hover {
        background-color: #b0b0b0;
      }
    }
  }
  .content {
    flex: 1;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: scroll;
  }
}
.logout {
  margin-left: auto;
}
</style>
